Component({
    properties: {
        keyCol:{type:String,value:'title'},
        valueCol:{type:String, value:'id'},
        options:{
            type:[Object,Array,null,undefined], value:null,
        },
        value:{
            type:[Object,String,Number], value:'',
        },
        placeholder: {type:String, value:"请选择"}
    },
    data: {
        _options:{},
        _index:-1,
    },
    observers:{
        'options, value, valueCol':function (options, value, valueCol){

            let index = -1
            if(options && value){
                index = options.findIndex(item => item[valueCol]==value)
            }

            this.setData({
                _index:index,
                _options:options,
            })
        }
    },
    lifetimes:{
        attached() {

        }
    },
    methods: {
        bindChange(e){

            const {value} = e.detail
            const {_options, valueCol} = this.data

            this.setData({
                _index: value,
            });

            this.triggerEvent('change', {
                value:_options[value][valueCol]
            })
        }
    }
});
